//
//  FuwutiaokuanVC.m
//  HYSJ
//
//  Created by jzb on 2018/2/26.
//  Copyright © 2018年 黄山锋. All rights reserved.
//

#import "FuwutiaokuanVC.h"
#import "FuwutiaokuanTableViewCell.h"

@interface FuwutiaokuanVC ()
{
    NSString *_article_content;
    NSString *_article_title;
}
@property (nonatomic,strong) FuwutiaokuanTableViewCell *cell;

@end

@implementation FuwutiaokuanVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"服务条款";
    self.view.backgroundColor = [UIColor whiteColor];
    
    _article_content = @"";
    _article_title = @"";
    
    [self setUpTableView];
    [self net_getSysArticle];
}
//配置tableView
-(void)setUpTableView{
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.frame = CGRectMake(10, 0, kScreenWidth-15, kScreenHeight);
    //注册cell
    [self registerCellWithCellClassArray:@[NSStringFromClass([FuwutiaokuanTableViewCell class])]];
}

#pragma mark -UITableViewDelegate,UITableViewDataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    self.cell = [tableView dequeueReusableCellWithIdentifier:[FuwutiaokuanTableViewCell getCellReuseIdentifier]];
    
    self.cell.TitleLabel.text = _article_title;
    NSMutableParagraphStyle  *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    
    // 行间距设置为30
    [paragraphStyle  setLineSpacing:10];
    
    paragraphStyle.firstLineHeadIndent=32;
    
    NSString  *testString = _article_content;
    NSMutableAttributedString  *setString = [[NSMutableAttributedString alloc] initWithString:testString];
    [setString  addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [testString length])];
    
    // 设置Label要显示的text
    [self.cell.fuwuLabel  setAttributedText:setString];
    
    return self.cell;
}

#pragma mark -网络请求
//获取用户信息
-(void)net_getSysArticle{
    [[DDNetworkManagerDate makeUrl_sysArticle_with_token:k_user_token article_id:@"1"] post_RequestFinshSuccess:^(id responseObject) {
        [self.tableView.mj_header endRefreshing];
        
        NSLog(@"-=-=>>%@",responseObject);
        if ([self requestFinshCode:responseObject isShowMessage:YES] == 1) {
            
            NSDictionary *data = [responseObject objectForKey:kRequsetDataKey];
            _article_title = [data objectForKey:@"article_title"];
            _article_content = [data objectForKey:@"article_content"];
        }
        
        //刷新
        [self.tableView reloadData];
    } failure:^(id errorObject) {
        [self.tableView.mj_header endRefreshing];
        [self showBottomMessag:@"网络请求失败"];
    }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
